<table id="jdThemeInfo_data"></table>
<script>
$(function(){
		var datagrid;
		var editRow=undefined;
		var op;
		datagrid=$('#jdThemeInfo_data').datagrid({   
		    url:'../jdThemeInfoServletBack',
		    queryParams:{op:"getThemeInfo"}, 
		    loadMsg:'努力加载数据中...',
		    fitColumns:true,
		    fit:true,
		    striped:true,
		    pagination:true,
		    pagePosition:'both',
		    rownumbers:true,
		    sortName:'jtid',
		    sortOrder:'asc',
		    remoteSort:false,
		    pageNumber:1,
		    pageSize:10,
		   	pageList:[10,20,30,40,50],			     
		    columns:[[   
		    	{field:'flag',title:'',checkbox:true,width:100,align:'center'},   
		        {field:'jtid',title:'主题编号',width:100,align:'center',sortable:true},   
		        {field:'tname',title:'游玩主题',width:100,align:'center',sortable:true,editor:{type:'text',options:{requeired:true}}}, 
		        {field:'temp',title:'主题介绍',width:200,align:'center',editor:{type:'text',options:{requeired:true}}}
		    ]],
		    toolbar: [{
		    	text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					op="addThemeInfo";
					if(editRow!=undefined){ 
						datagrid.datagrid("rejectChanges");
						datagrid.datagrid('endEdit', editRow );
						editRow=undefined;
					}
					
					if(editRow==undefined){
						datagrid.datagrid('insertRow',{index:0,row:{}});
						datagrid.datagrid("beginEdit",0);
						editRow=0;
					}
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					var rows=$('#jdThemeInfo_data').datagrid("getChecked")[0];
					if(rows==undefined){
						$.messager.show({title:'温馨提示',msg:'请选择要删除的数据...',timeout:2000,showType:'slide'});
					}else{		
						$.messager.confirm('信息确认', '您确定要删除选中的记录吗?', function(r){
							if (r){
								op="delThemeInfo";								
								var jtids="";
								var st=datagrid.datagrid("getSelections").length;
								for(var j=0;j<st-1;j++){
									jtids+=datagrid.datagrid("getSelections")[j].jtid+",";
								}
								jtids+=datagrid.datagrid("getSelections")[j].jtid;
								
								//向服务器发送请求
								$.post("../jdThemeInfoServletBack?t="+new Date(),{op:"delThemeInfo",jtids:jtids},function(data){
									data=parseInt($.trim(data));
									if(data>0){
										$.messager.show({title:'成功提示',msg:'主题信息删除成功...',timeout:3000,showType:'slide'});
										$('#jdThemeInfo_data').datagrid("reload");
									}else{
										$.messager.alert('失败提示','主题信息删除失败，请稍后重试...','error');
									}
								});
	
							}
							
						});
					}
				}
			},'-',{
		    	text:'修改',
				iconCls: 'icon-edit',
				handler: function(){
					var rows=$('#jdThemeInfo_data').datagrid("getChecked")[0];
					if(rows==undefined){
						$.messager.show({title:'温馨提示',msg:'请选择要修改的数据...',timeout:2000,showType:'slide'});
					}else{
						op="updateThemeInfo";
						if(editRow!=undefined){ 
							datagrid.datagrid("rejectChanges");
							datagrid.datagrid('endEdit', editRow); 
							editRow=undefined;
						}					
						if(editRow==undefined){
							var index=datagrid.datagrid("getRowIndex",rows);
							datagrid.datagrid('updateRow',{index:index,row:rows});
							datagrid.datagrid("beginEdit",index);
							editRow=index; 
						}
				   }
			}
		},'-',{
	    	text:'撤销',
			iconCls: 'icon-redo',
			handler: function(){
				datagrid.datagrid("rejectChanges");
				datagrid.datagrid('endEdit', editRow ); 
				editRow=undefined;
			}
		},'-',{
	    	text:'保存',
			iconCls: 'icon-save',
			handler: function(){
				datagrid.datagrid('endEdit',editRow); 
				var rows=datagrid.datagrid("getChanges")[0];
				if(rows==undefined){
					datagrid.datagrid("rejectChanges");
					datagrid.datagrid("unselectAll");
					editRow=undefined;
				}else{
					rows["op"]=op;
					$.post("../jdThemeInfoServletBack?t="+new Date(),rows,function(data){
						data=parseInt( $.trim(data) );
						if(data>0){
							$.messager.show({title:'成功提示',msg:'主题信息添加成功...',timeout:3000,showType:'slide'});
						}else{
							$.messager.alert('失败提示','主题信息添加失败，请稍后重试...','error');
						}						
						rows=null;
						datagrid.datagrid("reload");
						editRow=undefined;
						datagrid.datagrid("rejectChanges");
						datagrid.datagrid("unselectAll");
					});
				}
				
			}
		}]
	       
	}); 
}) 

$("#jdThemeInfo_data").datagrid('getPager').pagination({
	beforePageText:'第',
	afterPageText:'页 共{pages}页',
	displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
})
</script>

